<?php

namespace App\Repositories\Impl;

use App\Models\CulturalHeritageType;
use App\Repositories\Contracts\CulturalHeritageTypeRepository;
use App\Repositories\Transformers\CulturalHeritageTypeTransformer;

class CulturalHeritageTypeRepositoryImpl implements CulturalHeritageTypeRepository
{
    public function paginate($perPage, $filter)
    {
        $result = CulturalHeritageType::paginate($perPage);
        return $result;
    }

    public function getAll($param)
    {
        $culturalHeritageType = CulturalHeritageType::where($param)->get();

        $result = fractal($culturalHeritageType, new CulturalHeritageTypeTransformer());
        return $result->toArray();
    }

    public function find($id, $columns = ['*'])
    {
        return CulturalHeritageType::find($id, $columns);
    }

    public function findByFilter($filter, $columns = ['*'])
    {
        return CulturalHeritageType::where($filter)->first($columns);
    }

    public function store($data)
    {
        return CulturalHeritageType::create($data);
    }

    public function update($data, $id)
    {
        return CulturalHeritageType::whereId($id)->updateOrCreate($data);
    }

    public function updateByFilter($data, $where)
    {
        return CulturalHeritageType::where($where)->update($data);
    }

    public function delete($id)
    {
        return CulturalHeritageType::whereId($id)->delete();
    }
}
